/**
* Copyright 2009, Jethro Grassie, Creative Jar Technology Ltd (http://www.cjtech.co.uk)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
**/

package com.cjt.sample;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import javafx.animation.transition.*;

import com.cjt.sample.business.Services;
import com.cjt.sample.events.GetTimeEvent;


var model:Model = Model.getInstance();
var controller:Controller = Controller{};
var services:Services = Services{};


var textNode:Text;
var textTransition = SequentialTransition
{
    content:
    [
        FadeTransition
        {
            duration: 1s;
            node: bind textNode;
            fromValue: 0; toValue: 1;
        },
        PauseTransition
        {
            duration: 2s;
        },
        FadeTransition
        {
            duration: 1s;
            node: bind textNode;
            fromValue: 1; toValue: 0;
        }
    ]
}

Stage
{
    var scene:Scene;
    title: "CairngormFX Test";
    width: 400;
    height: 300;
    scene: scene = Scene
    {
        content:
        [
            Button
            {
                layoutX: 4;
                layoutY: 4;
                text: "Get the time";
                action: function():Void
                {
                    var event:GetTimeEvent = GetTimeEvent{};
                    event.dispatch();
                };
            },
            textNode = Text
            {
                override var content on replace
                {
                    textTransition.playFromStart();
                };
                layoutX: bind ((scene.width/2) - (textNode.layoutBounds.width/2));
                layoutY: bind (scene.height/2);
                font: Font { size: 12 };
                wrappingWidth: bind (scene.width - 8);
                textAlignment: TextAlignment.CENTER;
                content: bind model.lastResult;
            }
        ]
    }
}
